<template>
  <div class="bg-c-fff mb70 container min-height">
    <h2 class="box-title rel"><a href="#/index/help-center">内容管理-帮助中心</a> > {{id | titleFilter}}</h2>
    <ul>
      <li>
        <span>帮助标题：</span>
        <input type="text" class="input-css input-w1" v-model="roleName">
      </li>
      <li>
        <span>内容摘要：</span>
        <textarea class="vt" v-model="abstract"></textarea>
      </li>
      <li>
        <span>内容编辑：</span>
        <UE ref="ue"></UE>
      </li>
      <li>
        <span></span>
        <button class="blue-button xl-btn-css" @click="onSubmit">提交发布</button>
        <button class="xl-btn-css white-button" @click="onCancel">取消</button>
      </li>
    </ul>
  </div>
</template>
<script type="text/javascript">
import UE from '../components/UE'
export default {
  components: {
    UE
  },
  data() {
    return {
      roleName: '',
      abstract: '',
      id: ''
    }
  },
  mounted() {
    if (this.$route.query.id) {
      this.id = this.$route.query.id
      this.getContent()
    }
  },
  methods: {
    onSubmit() {
      if (!this.roleName) {
        this.$toasted.show('请输入帮助标题')
        return
      }
      if (!this.abstract) {
        this.$toasted.show('请输入内容摘要')
        return
      }
      let content = this.$refs.ue.getUEContent()
      if (!content) {
        this.$toasted.show('请输入帮助内容')
        return
      }
      this.$http.post('/sysContent/update', {
        title: this.roleName,
        roundup: this.abstract,
        content: content,
        type: 3,
        id: this.id
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$router.push('/index/help-center')
          if (this.id) {
            this.$toasted.show('编辑成功')
          } else {
            this.$toasted.show('发布成功')
          }
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
      })
    },
    onCancel() {
      this.$router.back()
    },
    getContent() {
      this.$http.get('/sysContent/detail/' + this.id).then(data => {
        if (data.data.httpCode === 200) {
          this.roleName = data.data.data.title
          this.abstract = data.data.data.roundup
          this.$refs.ue.setUEContent(data.data.data.content)
        } else {
          this.$toasted.show(data.data.data.msg)
        }
      }).catch(err => {
        console.log(err)
      })
    }
  },
  filters: {
    titleFilter(v) {
      if (v) {
        return '编辑帮助'
      } else {
        return '新增帮助'
      }
    }
  }
}

</script>
<style type="text/css" scoped>
.container {
  margin-top: 20px;
}

.min-height {
  min-height: 507px;
}

.box-title a {
  color: #a5a5a5;
}

ul {
  padding: 0 0 70px 190px;
}

ul li {
  padding: 10px 0;
}

ul li span {
  width: 194px;
  display: inline-block;
  text-align: right;
  color: #666666;
  margin-right: 20px;
}

textarea {
  width: 350px;
  height: 140px;
  padding: 10px;
}

button {
  margin-right: 45px;
}

</style>
